package de.csvparser.util.parser;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import de.csvparser.util.dataset.DataSet;

public class CSVParser<T> {

	private File file;
	
	public CSVParser(File file) {
		this.file = file;
	}
	
	public CSVParser(String name) {
		this.file = new File(name);
	}
	
	public DataSet<T> parseFile(String seperator) throws IOException {
		DataSet<T> dataSet = new DataSet<T>();
		BufferedReader br = new BufferedReader(new FileReader(file));
		String line = "";
		while((line = br.readLine()) != null) {
			@SuppressWarnings("unchecked")
			T[] data = (T[]) line.split(seperator);
			dataSet.addData(data);
		}
		br.close();
		return dataSet;
	}
	
}
